﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace WebSystem
{
    public partial class MClaAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button7_Click(object sender, EventArgs e)
        {
            Response.Redirect("MCla.aspx");
        }
        protected void Button4_Click(object sender, EventArgs e)
        {
            Response.Redirect("MClaAdd.aspx");
            //string strCn = "server=pc.hstc.cn;database=dhd2014115121;uid=2014115121;pwd=19960404";
            //SqlConnection cn = new SqlConnection(strCn);
            //try
            //{
            //    cn.Open();
            //    string strSql = "INSERT INTO Student (No, Name, Age, College) VALUES   (N'" + this.txtNo.Text + "', N'" + this.txtName.Text + "'," + this.txtAge.Text + ", N'" + this.txtCollege.Text + "')";
            //    SqlCommand cmd = new SqlCommand(strSql, cn);
            //    int iUpd = cmd.ExecuteNonQuery();
            //    if (iUpd < 1)
            //    {
            //        this.lblInfo.Text = "新增失败！";
            //    }
            //    else
            //    {
            //        this.lblInfo.Text = "新增" + iUpd.ToString() + "条记录！";
            //    }
            //}
            //catch (Exception ex)
            //{
            //    this.lblInfo.Text = ex.Message;
            //}
            //finally
            //{
            //    cn.Close();
            //}
        }
        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Session["Theme"] == "1")
            {
                Page.Theme = "1";
            }
            else if (Session["Theme"] == "3")
            {
                Page.Theme = "3";
            }

            else
            {
                Page.Theme = "2";
            }
        }
        protected void Button5_Click(object sender, EventArgs e)
        {
            Response.Redirect("MClaDel.aspx");
        }

        protected void Button6_Click(object sender, EventArgs e)
        {
            Response.Redirect("MClaUpd.aspx");
        }

        protected void btn_Click(object sender, EventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014115121;uid=2014115121;pwd=19960404";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                cn.Open();
                string strSql = "INSERT INTO Course (Cno,Cname,Credit,Tno) VALUES   (N'" + this.txtCno.Text + "', N'" + this.txtCname.Text + "'," + this.txtCre.Text + ", N'" + this.txtTno.Text + "')";
                SqlCommand cmd = new SqlCommand(strSql, cn);
                int iUpd = cmd.ExecuteNonQuery();
                if (iUpd < 1)
                {
                    this.lblInfo.Text = "新增失败，此课程已存在！";
                }
                else
                {
                    this.lblInfo.Text = "新增" + iUpd.ToString() + "条记录！";
                }
            }
            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }

        protected void Button8_Click(object sender, EventArgs e)
        {
            txtCno.Text = "";
            txtCname.Text = "";
            txtCre.Text = "";
            txtTno.Text = "";
            lblInfo.Text = "";
        }

        protected void Button8_Click1(object sender, EventArgs e)
        {

        }
    }
}